#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
THN TELEPORT version 2

Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

This library is dual-licensed.
  + For commercial software, please obtain a commercial license from THN Solutions LLC.

  + For free software, this library is licensed under GPL version 3. A summary of GPLv3 is
    listed below. You should also find a copy of GPLv3 as file License_GPLv3.txt included
	with the source-code files.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3 as published by
    the Free Software Foundation  of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
#region Using directives
using System;
using System.Diagnostics;
using System.Web.Services;
using System.ComponentModel;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
#endregion

namespace Thn.Communication.Teleporting.Connectors.WebService
{
    /// <summary>
    /// This is the default web service proxy when TeleportRequest method name is the default name and the namespace is http://tempuri.org/
    /// </summary>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.1433")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name = "TeleportServiceSoap", Namespace = "http://tempuri.org/")]
    public class WebServiceProxy : System.Web.Services.Protocols.SoapHttpClientProtocol, IWebServiceProxy
    {
        #region Url
        /// <summary>
        /// Gets/Sets the URL address to the webservice
        /// </summary>
        public new string Url
        {
            get
            {
                return base.Url;
            }
            set
            {
                if ((((this.IsLocalFileSystemWebService(base.Url) == true)
                            && (this.useDefaultCredentialsSetExplicitly == false))
                            && (this.IsLocalFileSystemWebService(value) == false)))
                {
                    base.UseDefaultCredentials = false;
                }
                base.Url = value;
            }
        }
        #endregion

        #region Use Default Credentials
        private bool useDefaultCredentialsSetExplicitly;

        /// <summary>
        /// Gets/Sets whether default credentials are used for web service authentication
        /// </summary>
        public new bool UseDefaultCredentials
        {
            get
            {
                return base.UseDefaultCredentials;
            }
            set
            {
                base.UseDefaultCredentials = value;
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        #endregion

        #region Teleport Request
        /// <summary>
        /// Invoke method TeleportRequest on web service
        /// </summary>
        public string TeleportRequest(string gateway, string method, string encodedArgs)
        {
            return WebMethod(gateway, method, encodedArgs);
        }
        #endregion

        #region WebMethod
        /// <summary>
        /// Invoke method TeleportRequest on web service
        /// </summary>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/WebMethod", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public string WebMethod(string gateway, string method, string encodedArgs)
        {
            object[] results = this.Invoke("WebMethod", new object[] {
                        gateway,
                        method,
                        encodedArgs});
            return ((string)(results[0]));
        }
        #endregion

        #region IsLocalFileSystemWebService
        private bool IsLocalFileSystemWebService(string url)
        {
            if (((url == null)
                        || (url == string.Empty)))
            {
                return false;
            }
            System.Uri wsUri = new System.Uri(url);
            if (((wsUri.Port >= 1024)
                        && (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0)))
            {
                return true;
            }
            return false;
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        public WebServiceProxy()
        {
            if ((this.IsLocalFileSystemWebService(this.Url) == true))
            {
                this.UseDefaultCredentials = true;
                this.useDefaultCredentialsSetExplicitly = false;
            }
            else
            {
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        #endregion
    }
}
